package io.sage.modules.warn.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import io.sage.modules.warn.enums.BRfidWarmConfTypeEnum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.sage.common.utils.R;
import io.sage.modules.warn.entity.BRfidWarn;
import io.sage.modules.warn.service.BRfidWarnService;
import io.swagger.annotations.Api;


/**
 * rfid报警记录
 *
 * @author xujh
 * @email jhang_mail@163.com
 * @date 2019-07-25 22:26:10
 */
@RestController
@RequestMapping("warn/brfidwarn")
@Api(tags="报警记录接口")
public class RfidWarnController {
	
	@Autowired
	private BRfidWarnService rfidWarnService;


	
	/**
	 * 报警记录列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	@RequiresPermissions("warn:brfidwarn:list")
    public R list(@RequestParam Map<String, Object> params){
    	
    	Integer pageSize = 1;
 		if (params != null && params.get("limit") != null) {
 			pageSize = java.lang.Integer.parseInt(params.get("limit").toString());
 		}
 		
 		Integer pageNum = 10;
 		if (params != null && params.get("page") != null) {
 			pageNum = java.lang.Integer.parseInt(params.get("page").toString());
 		}

 		HashMap<String, Object> paramMap = new HashMap<String, Object>();
 		if(params.get("createName")!=null){
 			if(!"".equals(params.get("createName").toString())){
 				paramMap.put("createName", params.get("createName").toString());
 			}
 		}

 		PageHelper.startPage(pageNum, pageSize);// 设置分页的起始码以及页面大小
 		List<BRfidWarn> selectRfidWarnList = rfidWarnService.selectRfidWarnList(paramMap);
 		
 		PageInfo<BRfidWarn> rfidWarnList = new PageInfo<BRfidWarn>(selectRfidWarnList);// 传入list就可以了

 		return R.ok().put("rfidWarnList", rfidWarnList);
    }
	@GetMapping("queryConfList")
	public R queryConfList(){
		return R.ok().put("warnConf", BRfidWarmConfTypeEnum.getList());
	}

	/**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("wechat:notice:info")
    public R info(@PathVariable("id") Integer id){
    	
    	if(id==null){
    		return R.error("id不能为空");
    	}
    	
    	BRfidWarn selectByPrimaryKey = rfidWarnService.selectByPrimaryKey(id);

        return R.ok().put("rfidWarn", selectByPrimaryKey);
    }




    
}
